home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / SmallTalk / IOCtl.st < prev    next >
Text File  |  1995-08-25  |  3KB  |  99 lines

  1. "======================================================================
  2. |
  3. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  4. | Written by Steve Byrne.
  5. |
  6. | This file is part of GNU Smalltalk.
  7. |
  8. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  9. | under the terms of the GNU General Public License as published by the Free
  10. | Software Foundation; either version 1, or (at your option) any later version.
  11. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  12. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  14. | details.
  15. | You should have received a copy of the GNU General Public License along with
  16. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  17. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  18. |
  19.  ======================================================================"
  20.  
  21. "
  22. |     Change Log
  23. | ============================================================================
  24. | Author       Date       Change 
  25. | sbb         16 Feb 92      created summer 90.
  26. |
  27. "
  28.  
  29. CObject variableWordSubclass: #IOCtl
  30.     instanceVariableNames: ''
  31.     classVariableNames: ''
  32.     poolDictionaries: ''
  33.     category: 'C interface hacking'
  34. !
  35.  
  36. IOCtl comment:
  37. 'I am a gross hack.  I exist because there is no LargeInteger support
  38. currently in GNU Smalltalk, and certain IO operations need to perform
  39. IOCtls.  I fully expect to be removed in the forseeable future'!
  40.  
  41. !IOCtl class methodsFor: 'instance creation'!
  42.  
  43. new
  44.     ^self new: 1        "leave room for the pointer"
  45. !
  46.  
  47. voidType: typeChar index: intIndex
  48.     ^self new init: 16r20 type: typeChar index: intIndex size: 0
  49. !
  50.  
  51. readType: typeChar index: intIndex struct: cStruct
  52.     ^self readType: typeChar index: intIndex size: cStruct sizeof
  53. !
  54.  
  55. readType: typeChar index: intIndex size: nBytes
  56.     ^self new init: 16r40 type: typeChar index: intIndex size: nBytes
  57. !
  58.     
  59. writeType: typeChar index: intIndex struct: cStruct
  60.     ^self writeType: typeChar index: intIndex size: cStruct sizeof
  61. !
  62.  
  63. writeType: typeChar index: intIndex size: nBytes
  64.     ^self new init: 16r80 type: typeChar index: intIndex size: nBytes
  65. !
  66.  
  67. readWriteType: typeChar index: intIndex struct: cStruct
  68.     ^self readWriteType: typeChar index: intIndex size: cStruct sizeof
  69. !
  70.  
  71. readWriteType: typeChar index: intIndex size: nBytes
  72.     ^self new init: 16rC0 type: typeChar index: intIndex size: nBytes
  73. !!
  74.  
  75.  
  76. !IOCtl methodsFor: 'private'!
  77.  
  78. init: magic type: typeChar index: intIndex size: nBytes
  79.     | lowBits highBits addr |
  80.     lowBits _ intIndex bitOr: ((typeChar asciiValue) bitShift: 8).
  81.     highBits _ (magic bitShift: 8) bitOr: (nBytes bitAnd: 16rFF).
  82.     " compute the address of where the pointer that the CObject contains
  83.       lives."
  84.     addr _ (Memory addressOf: self) + 8.
  85.     Bigendian
  86.     ifTrue: [ ByteMemory at: addr + 0 put: (highBits bitShift: -8).
  87.           ByteMemory at: addr + 1 put: (highBits bitAnd: 16rFF).
  88.           ByteMemory at: addr + 2 put: (lowBits bitShift: -8).
  89.           ByteMemory at: addr + 3 put: (lowBits bitAnd: 16rFF) ]
  90.     ifFalse: [ ByteMemory at: addr + 3 put: (highBits bitShift: -8).
  91.           ByteMemory at: addr + 2 put: (highBits bitAnd: 16rFF).
  92.           ByteMemory at: addr + 1 put: (lowBits bitShift: -8).
  93.           ByteMemory at: addr + 0 put: (lowBits bitAnd: 16rFF) ]
  94. ! !
  95.  
  96.  
  97.